package com.qianying.controller.admin;

import com.qianying.comment.CommonResult;
import com.qianying.entity.SysRolePermission;
import com.qianying.service.SysRolePermissionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 角色权限关联表 控制器
 */
@RestController
@RequestMapping("/admin/sysRolePermission")
@Tag(name = "角色权限关联管理", description = "角色与权限的关联关系管理接口")
public class SysRolePermissionController {

    @Autowired
    private SysRolePermissionService sysRolePermissionService;



    /**
     * 根据ID删除角色权限关联
     */
    @PostMapping("/delete/{id}")
    @Operation(
            summary = "根据ID删除角色权限关联",
            description = "通过关联记录ID删除特定的角色权限关联关系",
            parameters = {
                    @Parameter(name = "id", description = "关联记录主键ID", example = "5", required = true)
            }
    )
    public CommonResult<?> deleteById(@PathVariable Long id) {
        if (id == null) {
            return CommonResult.failed("关联记录ID不能为空");
        }
        return sysRolePermissionService.removeById(id);
    }

    /**
     * 新增角色权限关联
     */
    @PostMapping("/save")
    @Operation(
            summary = "新增角色权限关联",
            description = "建立角色与权限的关联关系，角色ID和权限ID为必填项",
            parameters = {
                    @Parameter(name = "roleId", description = "角色ID", example = "1", required = true),
                    @Parameter(name = "permissionId", description = "权限ID", example = "101", required = true)
            }
    )
    public CommonResult<?> saveRolePermission(@RequestBody SysRolePermission sysRolePermission) {

        return sysRolePermissionService.saveSysRolePermission(sysRolePermission);
    }
}
